@page "/systemlogs"
@attribute [TabItemOption(Text = "系统日志")]

<PageTitle>系统日志管理</PageTitle>

@if (_hasPermission)
{
    <div class="container-fluid">
    @if (_isReadOnly)
        {
            <div class="alert alert-warning">
                <i class="fa-solid fa-eye me-2"></i>
                    <strong>只读权限提示：</strong>您当前拥有只读权限，可以查看日志信息但无法导出。
            </div>
        }

        <Table TItem="Application.Core.Entity.SystemLog" AutoGenerateColumns="false" class="table-demo"
               IsPagination="true" PageItems="20" PageItemsSource="PageItemsSource"
               IsStriped="true" IsBordered="true" IsMultipleSelect="true" AllowResizing="true"
               ShowSkeleton="true" ShowToolbar="true" ShowAddButton="false" ShowEditButton="false" ShowDeleteButton="false" 
               ShowSearch="true" ShowExtendButtons="false"
               ShowExportButton="@(!_isReadOnly)"
               OnQueryAsync="OnQueryAsync"
               IsAutoRefresh="true" AutoRefreshInterval="2000">
               <TableColumns>
                    <TableColumn @bind-Field="@context.CreateTime" Width="180" Sortable="true" Filterable="true">
                        <DisplayTemplate>
                            @context.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        </DisplayTemplate>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.Level" Width="100" Sortable="true" Filterable="true" Searchable="true">
                        <SearchTemplate Context="model">
                                <div class="col-12 col-sm-6">
                                    <Select Items="SearchItems" @bind-Value="@model!.Level" ShowLabel="true" DisplayText="日志级别"></Select>
                                </div>
                            </SearchTemplate>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.Message" Sortable="true" Filterable="true" Searchable="true" />
                    <TableColumn @bind-Field="@context.Exception" Sortable="true" Filterable="true" Searchable="true" />
                    <TableColumn @bind-Field="@context.CallerMemberName" Width="120" Sortable="true" Filterable="true" />
                    <TableColumn @bind-Field="@context.CallerFilePath" Width="200" Sortable="true" Filterable="true" Searchable="true" />
                    <TableColumn @bind-Field="@context.CallerLineNumber" Width="80" Sortable="true" Filterable="true" />
               </TableColumns>
        </Table>
    </div>
}
else
{
    <div class="container-fluid d-flex align-items-center justify-content-center" style="height: 80vh;">
        <div class="text-center">
            <div class="mb-4">
                <i class="fa-solid fa-ban fa-5x text-danger"></i>
            </div>
            <h1 class="display-4 text-danger mb-3">访问被拒绝</h1>
            <p class="lead mb-4">您没有权限访问系统日志页面。</p>
            <button class="btn btn-primary" @onclick="GoToHome">
                <i class="fa-solid fa-home me-2"></i>返回首页
            </button>
        </div>
    </div>
}

